using System;
using System.Collections.ObjectModel;
using System.Drawing;
using System.Web.UI;
using Barbar.MapReport.Common;
using Barbar.MapReport.Common.Drawing;
using Barbar.MapReport.Common.Drawing.Commands;
using Barbar.MapReport.Common.Drawing.ValueIndicators;
using Barbar.MapReport.Configuration;
using Barbar.MapReport.HtmlRender;

public partial class CampaignTargetsReport : MapReportDemoPage {
  protected void Page_Load(object sender, EventArgs e) {
    Collection<BusinessGeoPoint> points = new Collection<BusinessGeoPoint>();
    foreach (Contact contact in DataProvider.Instance.Contacts) {
      if (!contact.Latitude.HasValue || !contact.Longitude.HasValue)
        continue;
      BusinessGeoPoint point = new BusinessGeoPoint();
      point.Latitude = contact.Latitude.Value;
      point.Longitude = contact.Longitude.Value;
      point.Value1 = 1.0m;
      point.ToolTip = String.Format(@"
<table cellspacing=""0"" colpadding=""0"" border=""0"">
  <tr><td class=""fieldBold"" valign=""top"">Name:</td><td class=""field"" valign=""top"" style=""font-weight:normal;"">{0}</td></tr>
  <tr><td class=""fieldBold"" valign=""top"">Street:</td><td class=""field"" valign=""top"" style=""font-weight:normal;"">{1}</td></tr>
  <tr><td class=""fieldBold"" valign=""top"">City:</td><td class=""field"" valign=""top"" style=""font-weight:normal;"">{2}</td></tr>
  <tr><td class=""fieldBold"" valign=""top"">Country:</td><td class=""field"" valign=""top"" style=""font-weight:normal;"">{3}</td></tr>
</table><br/>", contact.ContactName, contact.Street, contact.City, contact.Country);
      point.ToolTipForAggregation = String.Format(@"<tr>{0}</tr>", point.ToolTip);
      points.Add(point);
    }

    RenderingService service = new RenderingService();

    AddDynamicValueIndicatorsCommand cmd = new AddDynamicValueIndicatorsCommand();
    cmd.Points = points;
    ListProperties properties = new ListProperties();
    properties.Color = new SerializedColor();
    properties.Color.Color = Color.Green;
    properties.ToolTipTemplate = @"<span class=""field"">Contacts count:{Count}</span><div style=""width:200px; height:120px; overflow:auto;""><table>{Content}</table></div>";
    cmd.Properties = properties;
    cmd.Radius = 7;

    service.Execute(cmd);

    RenderSettings settings = new RenderSettings(new SerializedUnit(800), new SerializedUnit(600), 51, 11, 6, MapConfigurationManager.MapSettings.GoogleKeyProvider.DefaultGoogleKey, 2057);
    settings.ShowLegend = false;
    settings.EnableGoogleBar = true;

    MapHtmlFragment fragment = service.Render(settings);

    litMapDiv.Text = fragment.MapElement;
  }
}
